package org.apache.jsp;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.List;

public class Track {

	public static String catchStr(String str,StringBuffer store){
		store.append(str);
		return str;
	}
	
	
	public void creatFile(StringBuffer sb){
		System.out.println(sb);
	}
	public static int catchStr(int str,StringBuffer store){
		store.append((char)str);
		return str;
	}
	public static void main(String[] args) throws Exception {
		String file= "genTableForm_jsp";
		String f = "D:\\openCode\\gokplus\\jeeplus3.0\\creak\\org\\apache\\jsp\\webpage\\modules\\gen\\"+file+".java";
		String t = "D:\\openCode\\gokplus\\jeeplus3.0\\creak\\org\\apache\\jsp\\webpage\\modules\\gen\\"+file+"2.java";
		fileRead(f,t);
		
		
		
//		files("D:\\openCode\\gokplus\\jeeplus3.0\\creak\\org\\apache\\jsp\\webpage\\modules\\gen");
	}
	
	public static File[] files(String fileName) throws Exception{
		File ii = new File(fileName);
		for (File ff : ii.listFiles()) {
			fileR(ff);
		}
		
		return	ii.listFiles();
	}
	
	public static void fileR(File ff) throws Exception{
		BufferedReader br = new BufferedReader(new FileReader(ff));
		String line  = null;
		while((line=br.readLine())!=null){
			
			
			if(line.replace(",store));", "^^").split("^^").length>0){
				System.out.println(line);
System.out.println(ff.getName());			}
		}
		br.close();
	}
	
	
	
	
	
	public static void fileRead(String fileName,String fileTo) throws Exception{
		File f= new File(fileName);
		System.out.println(f.exists());
		BufferedReader br = new BufferedReader(new FileReader(new File(fileName)));
		BufferedWriter bw  = new BufferedWriter(new FileWriter(new File(fileTo)));
		String line  = null;
		while((line=br.readLine())!=null){
			
//			line =	line.replace("JspWriter out", "StringBuffer store = new StringBuffer(); JspWriter out");
			
			if(line.contains("out.write")&&!line.contains("out.write(Trac")){
			line = line.replace("out.write(", "out.write(Track.catchStr(");
			line =line.substring(0, line.length()-2)+",store));";
			}
			System.out.println(line);
			bw.write(line);bw.newLine();
		}
		br.close();
		bw.flush();bw.close();
	}
}
